home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume5 / xview.demos / part01 next >
Encoding:
Internet Message Format  |  1989-12-07  |  59.6 KB

  1. Path: uunet!island!sun.com
  2. From: argv@sun.com (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v05i039: XView example programs, Part01/06
  5. Message-ID: <1239@island.uu.net>
  6. Date: 8 Dec 89 07:37:06 GMT
  7. Sender: argv@island.uu.net
  8. Lines: 1657
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Dan Heller <argv@sun.com>
  12. Posting-number: Volume 5, Issue 39
  13. Archive-name: xview.demos/part01
  14.  
  15. This directory contains all the demo programs from the XView Programmer's
  16. Manual (XVPM), which is Volume 7 of the series of X books from O'Reilly
  17. Associates.
  18. The book should be available (in book stores) by January.  XView will be
  19. distributed by Sun Microsystems and will also be on the X11R4 release.
  20. The XVPM and all its programs were written by me, Dan heller <argv@sun.com>.
  21.  
  22. Contact xview@ora.uu.net for information on ordering books.
  23.  
  24. Contact xviewbugs@sun.com for bugs with XView or other related questions.
  25.  
  26. Buy the book if you have questions about any of the programs. :-)
  27. Or mail argv@sun.com or xviewbugs@sun.com for help.
  28.  
  29. --------------
  30. What is XView?
  31. --------------
  32. Basically, XView is a toolkit for developing Open Look user interfaces
  33. for X11-based applications.  It does *not* use the toolkit intrinsics,
  34. but it has a similar class-inheritance type system where you can build
  35. new packages based on existing ones.  However, XView was written to make
  36. Open Look compliant applications, so you won't be able to write a Motif
  37. interface using XView, for example.  You aren't required to use an Open
  38. Look window manager, but it'll help bring out some very important aspects
  39. of the toolkit.
  40.  
  41. ----------------------------
  42. What's in this distribution?
  43. ----------------------------
  44. The sources include several directories for each XView "object".
  45. Objects include panels, canvases, frames, and so on.  Each directory
  46. contains sample programs that focus on the particular packages.  Also
  47. included are Makefiles and Imakefiles.  The Imakefiles are the same
  48. as those that are going to be distirbuted by Sun and available on
  49. the X11R4 release of XView.  The Imakefiles probably won't work
  50. right now unless you fiddle with them a little.  The makefiles
  51. are pretty straightforward.  Basically, most programs[%] compile as:
  52.     cc program.c -lxview -lX11 -o program
  53. If the include files for your XView sources are not in /usr/include,
  54. then be sure to add -I"path" to the compile-line indicating the
  55. path to these include files.
  56.  
  57. [%] There is one exception -- ttysw/ttycurses.c also uses the curses
  58. library demonstrating how you can use it with the terminal emulator window.
  59.  
  60.    File Name        Archive #    Description
  61. ----------------------------------------------------------
  62.  xview.demos                1    
  63.  xview.demos/Imakefile      5    
  64.  xview.demos/canvas         1    
  65.  xview.demos/canvas/Imakefile  5    
  66.  xview.demos/canvas/Makefile  5    
  67.  xview.demos/canvas/canvas_event.c  3    
  68.  xview.demos/canvas/canvas_input.c  2    
  69.  xview.demos/canvas/line.c  5    
  70.  xview.demos/canvas/scroll_view.c  2    
  71.  xview.demos/canvas/split_views.c  2    
  72.  xview.demos/color          1    
  73.  xview.demos/color/Imakefile  5    
  74.  xview.demos/color/Makefile  6    
  75.  xview.demos/color/cardback.icon  4    
  76.  xview.demos/color/color.c  4    
  77.  xview.demos/color/color_animate.c  3    
  78.  xview.demos/color/color_logo.c  3    
  79.  xview.demos/color/color_objs.c  1    
  80.  xview.demos/color/x_draw.c  2    
  81.  xview.demos/cursor         1    
  82.  xview.demos/cursor/Imakefile  5    
  83.  xview.demos/cursor/Makefile  6    
  84.  xview.demos/cursor/hot_spot.c  4    
  85.  xview.demos/cursor/simple_cursor.c  5    
  86.  xview.demos/cursor/stop_cursor.c  5    
  87.  xview.demos/defaults       1    
  88.  xview.demos/defaults/Imakefile  5    
  89.  xview.demos/defaults/Makefile  6    
  90.  xview.demos/defaults/default_size.c  5    
  91.  xview.demos/defaults/default_text.c  5    
  92.  xview.demos/fonts          1    
  93.  xview.demos/fonts/Imakefile  5    
  94.  xview.demos/fonts/Makefile  6    
  95.  xview.demos/fonts/fonts.c  1    
  96.  xview.demos/fonts/simple_font.c  4    
  97.  xview.demos/fonts/type_font.c  4    
  98.  xview.demos/frames         1    
  99.  xview.demos/frames/Imakefile  5    
  100.  xview.demos/frames/Makefile  6    
  101.  xview.demos/frames/frame_color.c  6    
  102.  xview.demos/frames/simple_frame.c  6    
  103.  xview.demos/frames/subframe.c  6    
  104.  xview.demos/icons          1    
  105.  xview.demos/icons/Imakefile  6    
  106.  xview.demos/icons/Makefile  6    
  107.  xview.demos/icons/closed.icon  4    
  108.  xview.demos/icons/icon_demo.c  5    
  109.  xview.demos/icons/open.icon  5    
  110.  xview.demos/menus          1    
  111.  xview.demos/menus/Imakefile  5    
  112.  xview.demos/menus/Makefile  6    
  113.  xview.demos/menus/menu.c   4    
  114.  xview.demos/menus/menu_dir.c  3    
  115.  xview.demos/menus/menu_dir2.c  2    
  116.  xview.demos/menus/pin_menu.c  2    
  117.  xview.demos/menus/simple_menu.c  4    
  118.  xview.demos/menus/xv_menu.c  4    
  119.  xview.demos/misc           1    
  120.  xview.demos/misc/Imakefile  5    
  121.  xview.demos/misc/Makefile  6    
  122.  xview.demos/misc/drag_n_drop.c  3    
  123.  xview.demos/misc/fullscreen.c  4    
  124.  xview.demos/misc/screen.c  5    
  125.  xview.demos/misc/svrimage.c  5    
  126.  xview.demos/misc/type_to_string.c  5    
  127.  xview.demos/notice         1    
  128.  xview.demos/notice/Imakefile  5    
  129.  xview.demos/notice/Makefile  6    
  130.  xview.demos/notice/notice.c  3    
  131.  xview.demos/notice/simple_notice.c  5    
  132.  xview.demos/notice/trigger_notice.c  4    
  133.  xview.demos/notifier       1    
  134.  xview.demos/notifier/Imakefile  5    
  135.  xview.demos/notifier/Makefile  6    
  136.  xview.demos/notifier/animate.c  4    
  137.  xview.demos/notifier/interpose.c  5    
  138.  xview.demos/notifier/notify_input.c  5    
  139.  xview.demos/notifier/ntfy_do_dis.c  5    
  140.  xview.demos/notifier/ntfy_pipe.c  3    
  141.  xview.demos/notifier/ntfy_sig.c  5    
  142.  xview.demos/panels         1    
  143.  xview.demos/panels/Imakefile  4    
  144.  xview.demos/panels/Makefile  6    
  145.  xview.demos/panels/btn_menu.c  5    
  146.  xview.demos/panels/choices.c  3    
  147.  xview.demos/panels/client_data.c  5    
  148.  xview.demos/panels/item_move.c  1    
  149.  xview.demos/panels/list_glyphs.c  4    
  150.  xview.demos/panels/panel_repaint.c  4    
  151.  xview.demos/panels/repaint.c  5    
  152.  xview.demos/panels/simple_panel.c  5    
  153.  xview.demos/panels/stop_frame.c  5    
  154.  xview.demos/scrollbar      1    
  155.  xview.demos/scrollbar/Imakefile  5    
  156.  xview.demos/scrollbar/Makefile  6    
  157.  xview.demos/scrollbar/scroll_cells.c  1    
  158.  xview.demos/scrollbar/scroll_cells2.c  1    
  159.  xview.demos/seln_svc       1    
  160.  xview.demos/seln_svc/Imakefile  5    
  161.  xview.demos/seln_svc/Makefile  6    
  162.  xview.demos/seln_svc/long_seln.c  2    
  163.  xview.demos/seln_svc/seln.c  2    
  164.  xview.demos/seln_svc/seln_line.c  4    
  165.  xview.demos/seln_svc/simple_seln.c  4    
  166.  xview.demos/seln_svc/text_seln.c  3    
  167.  xview.demos/sv_compat      1    
  168.  xview.demos/sv_compat/Imakefile  5    
  169.  xview.demos/sv_compat/Makefile  6    
  170.  xview.demos/sv_compat/gray_stencil.pr  4    
  171.  xview.demos/sv_compat/pw_draw.c  4    
  172.  xview.demos/textsw         1    
  173.  xview.demos/textsw/Imakefile  6    
  174.  xview.demos/textsw/Makefile  6    
  175.  xview.demos/textsw/textsw.c  6    
  176.  xview.demos/textsw/textsw.font.c  3    
  177.  xview.demos/ttysw          1    
  178.  xview.demos/ttysw/Imakefile  5    
  179.  xview.demos/ttysw/Makefile  6    
  180.  xview.demos/ttysw/sample_tty.c  6    
  181.  xview.demos/ttysw/textsw_to_ttysw.c  5    
  182.  xview.demos/ttysw/ttycurses.c  1    
  183.  xview.demos/ttysw/xv_termsw.c  5    
  184.  
  185. #! /bin/sh
  186. # This is a shell archive.  Remove anything before this line, then feed it
  187. # into a shell via "sh file" or similar.  To overwrite existing files,
  188. # type "sh file -c".
  189. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  190. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  191. # If this archive is complete, you will see the following message at the end:
  192. #        "End of archive 1 (of 6)."
  193. # Contents:  xview.demos xview.demos/canvas xview.demos/color
  194. #   xview.demos/color/color_objs.c xview.demos/cursor
  195. #   xview.demos/defaults xview.demos/fonts xview.demos/fonts/fonts.c
  196. #   xview.demos/frames xview.demos/icons xview.demos/menus
  197. #   xview.demos/misc xview.demos/notice xview.demos/notifier
  198. #   xview.demos/panels xview.demos/panels/item_move.c
  199. #   xview.demos/scrollbar xview.demos/scrollbar/scroll_cells.c
  200. #   xview.demos/scrollbar/scroll_cells2.c xview.demos/seln_svc
  201. #   xview.demos/sv_compat xview.demos/textsw xview.demos/ttysw
  202. #   xview.demos/ttysw/ttycurses.c
  203. # Wrapped by argv@island on Thu Dec  7 23:18:13 1989
  204. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  205. if test ! -d 'xview.demos' ; then
  206.     echo shar: Creating directory \"'xview.demos'\"
  207.     mkdir 'xview.demos'
  208. fi
  209. if test ! -d 'xview.demos/canvas' ; then
  210.     echo shar: Creating directory \"'xview.demos/canvas'\"
  211.     mkdir 'xview.demos/canvas'
  212. fi
  213. if test ! -d 'xview.demos/color' ; then
  214.     echo shar: Creating directory \"'xview.demos/color'\"
  215.     mkdir 'xview.demos/color'
  216. fi
  217. if test -f 'xview.demos/color/color_objs.c' -a "${1}" != "-c" ; then 
  218.   echo shar: Will not clobber existing file \"'xview.demos/color/color_objs.c'\"
  219. else
  220. echo shar: Extracting \"'xview.demos/color/color_objs.c'\" \(8143 characters\)
  221. sed "s/^X//" >'xview.demos/color/color_objs.c' <<'END_OF_FILE'
  222. X/*
  223. X * color_objs.c --
  224. X *    This program demonstrates the use of color in XView. It allows
  225. X *    the user to choose the foreground and background colors of the
  226. X *    various objects in an interactive manner.
  227. X */
  228. X#include <X11/Xlib.h>
  229. X#include <xview/xview.h>
  230. X#include <xview/svrimage.h>
  231. X#include <xview/textsw.h>
  232. X#include <xview/panel.h>
  233. X#include <xview/icon.h>
  234. X#include <xview/cms.h>
  235. X
  236. X#define SELECT_TEXTSW           0
  237. X#define SELECT_TEXTSW_VIEW      1
  238. X#define SELECT_SCROLLBAR        2
  239. X#define SELECT_PANEL            3
  240. X#define SELECT_ICON             4
  241. X
  242. X#define NUM_COLORS              8
  243. X
  244. X/* Icon data */
  245. Xstatic short icon_bits[256]={
  246. X#include "cardback.icon"
  247. X};
  248. X
  249. XPanel_item      objects;
  250. XTextsw          textsw;
  251. XPanel           panel;
  252. XIcon            icon;
  253. X
  254. X/*
  255. X * main()
  256. X *    Create a panel and panel items. The application uses panel items
  257. X *    to choose a particular object and change its foreground and
  258. X *    background colors in an interactive manner. Create a textsw.
  259. X *    Create an icon. All the objects share the same colormap segment.
  260. X */
  261. Xmain(argc,argv)
  262. Xint     argc;
  263. Xchar    *argv[];
  264. X{
  265. X    Frame         frame;
  266. X    Panel_item    panel_palette, panel_fg_bg;
  267. X    Xv_cmsdata    cms_data;
  268. X    unsigned char red[NUM_COLORS], green[NUM_COLORS], blue[NUM_COLORS];
  269. X    Server_image  chips[NUM_COLORS], icon_image;
  270. X    void          color_notify();
  271. X    extern void   exit();
  272. X
  273. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  274. X
  275. X    /* Set up the RGB values and initialize the cms */
  276. X    initialize_cms_data(&cms_data, red, green, blue);
  277. X
  278. X    frame = (Frame)xv_create(NULL, FRAME,
  279. X        FRAME_LABEL,    argv[0],
  280. X        NULL);
  281. X
  282. X    /* Create panel and set the colormap segment on the panel */
  283. X    panel = (Panel)xv_create(frame, PANEL,
  284. X        PANEL_LAYOUT,   PANEL_VERTICAL,
  285. X        WIN_CMS_NAME,   "palette",
  286. X        WIN_CMS_DATA,   &cms_data,
  287. X        NULL);
  288. X
  289. X    /* Create panel items */
  290. X    objects = (Panel_item)xv_create(panel, PANEL_TOGGLE,
  291. X        PANEL_LABEL_STRING,     "Objects",
  292. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  293. X        PANEL_CHOICE_STRINGS,   "Textsw", "Textsw View",
  294. X                                "Scrollbar", "Panel", "Icon", NULL,
  295. X        NULL);
  296. X
  297. X    panel_fg_bg = (Panel_item)xv_create(panel, PANEL_CHECK_BOX,
  298. X        PANEL_LABEL_STRING,     "Fg/Bg",
  299. X        PANEL_CHOOSE_ONE,       TRUE,
  300. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  301. X        PANEL_CHOICE_STRINGS,   "Background", "Foreground", NULL,
  302. X        NULL);
  303. X
  304. X    /* Initialize colored chips to be used as panel choice images */
  305. X    initialize_chips(panel, chips);
  306. X    panel_palette = (Panel_item)xv_create(panel, PANEL_CHOICE,
  307. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  308. X        PANEL_LABEL_STRING,     "Colors",
  309. X        PANEL_CLIENT_DATA,      panel_fg_bg,
  310. X        XV_X,                   (int)xv_get(panel_fg_bg, XV_X),
  311. X        PANEL_NEXT_ROW,         15,
  312. X        PANEL_CHOICE_IMAGES,
  313. X            chips[0], chips[1], chips[2], chips[3], chips[4],
  314. X            chips[5], chips[6], chips[7], NULL,
  315. X        PANEL_NOTIFY_PROC,      color_notify,
  316. X        NULL);
  317. X
  318. X    (void) xv_create(panel, PANEL_BUTTON,
  319. X        PANEL_LABEL_STRING,     "Quit",
  320. X        PANEL_NOTIFY_PROC,      exit,
  321. X        NULL);
  322. X    (void)window_fit_height(panel);
  323. X
  324. X    /* create textsw and set the colormap segment for it */
  325. X    textsw = (Textsw)xv_create(frame, TEXTSW,
  326. X       WIN_CMS_NAME,    "palette",
  327. X       WIN_BELOW,       panel,
  328. X       WIN_ROWS,        15,
  329. X       WIN_COLUMNS,     80,
  330. X       NULL);
  331. X
  332. X    /* adjust panel dimensions */
  333. X    (void)xv_set(panel, WIN_WIDTH, xv_get(textsw, WIN_WIDTH), NULL);
  334. X
  335. X    icon_image = (Server_image)xv_create(NULL, SERVER_IMAGE,
  336. X        XV_WIDTH,               64,
  337. X        XV_HEIGHT,              64,
  338. X        SERVER_IMAGE_DEPTH,     1,
  339. X        SERVER_IMAGE_BITS,      icon_bits,
  340. X        NULL);
  341. X    /* associate icon with the base frame */
  342. X    icon = (Icon)xv_create(XV_NULL, ICON,
  343. X         ICON_IMAGE,    icon_image,
  344. X         WIN_CMS_NAME,  "palette",
  345. X         NULL);
  346. X    xv_set(frame, FRAME_ICON, icon, NULL);
  347. X
  348. X    window_fit(frame);
  349. X
  350. X    xv_main_loop(frame);
  351. X}
  352. X
  353. X/*
  354. X * initialize_cms_data()
  355. X *    Initialize the colormap segment data and setup the RGB values.
  356. X */
  357. Xinitialize_cms_data(cms_data, red, green, blue)
  358. XXv_cmsdata      *cms_data;
  359. Xunsigned char   *red, *green, *blue;
  360. X{
  361. X    /* white  */ (red)[0] = 255;  (green)[0] = 255;  (blue)[0] = 255;
  362. X    /* red    */ (red)[1] = 255;  (green)[1] = 0;    (blue)[1] = 0;
  363. X    /* green  */ (red)[2] = 0;    (green)[2] = 255;  (blue)[2] = 0;
  364. X    /* blue   */ (red)[3] = 0;    (green)[3] = 0;    (blue)[3] = 255;
  365. X    /* yellow */ (red)[4] = 255;  (green)[4] = 255;  (blue)[4] = 0;
  366. X    /* brown  */ (red)[5] = 188;  (green)[5] = 143;  (blue)[5] = 143;
  367. X    /* gray   */ (red)[6] = 220;  (green)[6] = 220;  (blue)[6] = 220;
  368. X    /* black  */ (red)[7] = 0;    (green)[7] = 0;    (blue)[7] = 0;
  369. X
  370. X    cms_data->type = XV_STATIC_CMS;
  371. X    cms_data->size = NUM_COLORS;
  372. X    cms_data->rgb_count = NUM_COLORS;
  373. X    cms_data->index = 0;
  374. X    cms_data->red = red;
  375. X    cms_data->green = green;
  376. X    cms_data->blue = blue;
  377. X}
  378. X
  379. X/*
  380. X * initialize_chips()
  381. X *    Create colored server images (pixmaps) to be used as
  382. X * panel choice images.
  383. X */
  384. Xinitialize_chips(panel, chips)
  385. XPanel           panel;
  386. XServer_image    chips[];
  387. X{
  388. X    register int   i;
  389. X    Display       *dpy = (Display *)xv_get(panel, XV_DISPLAY);
  390. X    unsigned long  mask, *pixels;
  391. X    XGCValues      values;
  392. X    Pixmap         pixmap;
  393. X    GC             gc;
  394. X
  395. X    if (DefaultDepth(dpy, DefaultScreen(dpy)) == 1) {
  396. X        puts("You need a color display to run this program");
  397. X        exit(1);
  398. X    }
  399. X    /* setup gc for drawing colord squares (chips) */
  400. X    values.graphics_exposures = False;
  401. X    values.foreground = 1;
  402. X    mask = GCGraphicsExposures | GCForeground;
  403. X    gc = XCreateGC(dpy,
  404. X        RootWindow(dpy, DefaultScreen(dpy)), mask, &values);
  405. X
  406. X    /* Get the actual X pixel values from the colormap.  The colormap
  407. X     * has been installed on the panel, so use that.  Any window with
  408. X     * a cms colormap will do.
  409. X     */
  410. X    pixels = (unsigned long *)xv_get(panel, WIN_X_COLOR_INDICES);
  411. X    for(i = 0; i < NUM_COLORS; i++) {
  412. X        chips[i] = (Server_image)xv_create(XV_NULL, SERVER_IMAGE,
  413. X            SERVER_IMAGE_COLORMAP, "palette",
  414. X            XV_WIDTH,           16,
  415. X            XV_HEIGHT,          16,
  416. X            SERVER_IMAGE_DEPTH, 8,
  417. X            NULL);
  418. X        XSetForeground(dpy, gc, pixels[i]);
  419. X        pixmap = (Pixmap)xv_get(chips[i], XV_XID);
  420. X        XFillRectangle(dpy, pixmap, gc, 0, 0, 16, 16);
  421. X    }
  422. X}
  423. X
  424. X/*
  425. X * This routine gets called when a color selection is made.
  426. X * Set the foreground or background on the currently selected object.
  427. X * WIN_FOREGROUND_COLOR & WIN_BACKGROUND_COLOR allow the application
  428. X * to specify indices into the colormap segment as the foreground
  429. X * and background values.
  430. X */
  431. Xvoid
  432. Xcolor_notify(panel_item, choice, event)
  433. XPanel_item      panel_item;
  434. Xint             choice;
  435. XEvent           *event;
  436. X{
  437. X    int cnt;
  438. X    Xv_opaque get_object();
  439. X    unsigned objs = (unsigned)xv_get(objects, PANEL_VALUE);
  440. X    int fg = (int)xv_get(xv_get(panel_item, PANEL_CLIENT_DATA),
  441. X                     PANEL_VALUE);
  442. X
  443. X    /* the value of the objects panel item is a bit mask ... "on" bits
  444. X     * mean that the choice is selected.  Get the object associated
  445. X     * with the choice and set it's color.  "&" tests bits in a mask.
  446. X     */
  447. X    for (cnt = 0; objs; cnt++, objs >>= 1)
  448. X        if (objs & 1)
  449. X            xv_set(get_object(cnt),
  450. X                fg? WIN_FOREGROUND_COLOR : WIN_BACKGROUND_COLOR,
  451. X                choice, NULL);
  452. X}
  453. X
  454. X/*
  455. X *    Return the XView handle to nth object.
  456. X */
  457. XXv_opaque
  458. Xget_object(n)
  459. Xint n;
  460. X{
  461. X    switch (n) {
  462. X        case SELECT_TEXTSW:
  463. X            return textsw;
  464. X        case SELECT_TEXTSW_VIEW:
  465. X            return xv_get(textsw, OPENWIN_NTH_VIEW, 0);
  466. X        case SELECT_SCROLLBAR:
  467. X            return xv_get(textsw, OPENWIN_VERTICAL_SCROLLBAR,
  468. X                                  xv_get(textsw, OPENWIN_NTH_VIEW, 0));
  469. X        case SELECT_PANEL:
  470. X            return panel;
  471. X        case SELECT_ICON:
  472. X            return icon;
  473. X        default:
  474. X            return textsw;
  475. X    }
  476. X}
  477. END_OF_FILE
  478. if test 8143 -ne `wc -c <'xview.demos/color/color_objs.c'`; then
  479.     echo shar: \"'xview.demos/color/color_objs.c'\" unpacked with wrong size!
  480. fi
  481. # end of 'xview.demos/color/color_objs.c'
  482. fi
  483. if test ! -d 'xview.demos/cursor' ; then
  484.     echo shar: Creating directory \"'xview.demos/cursor'\"
  485.     mkdir 'xview.demos/cursor'
  486. fi
  487. if test ! -d 'xview.demos/defaults' ; then
  488.     echo shar: Creating directory \"'xview.demos/defaults'\"
  489.     mkdir 'xview.demos/defaults'
  490. fi
  491. if test ! -d 'xview.demos/fonts' ; then
  492.     echo shar: Creating directory \"'xview.demos/fonts'\"
  493.     mkdir 'xview.demos/fonts'
  494. fi
  495. if test -f 'xview.demos/fonts/fonts.c' -a "${1}" != "-c" ; then 
  496.   echo shar: Will not clobber existing file \"'xview.demos/fonts/fonts.c'\"
  497. else
  498. echo shar: Extracting \"'xview.demos/fonts/fonts.c'\" \(7864 characters\)
  499. sed "s/^X//" >'xview.demos/fonts/fonts.c' <<'END_OF_FILE'
  500. X/*
  501. X * fonts.c -- provide an interface for the user to pick and choose
  502. X * between font families and styles known to XView.  The program
  503. X * provides several panel buttons to choose between font types, and
  504. X * a canvas window in which the user can type.  The characters typed
  505. X * are printed in the current font.  If a font "name" is specified,
  506. X * then the family, style and size are ignored.  Using the SELECT
  507. X * button on the canvas window positions the current typing location
  508. X * at the x,y coordinates of the button-down event.
  509. X */
  510. X#include <ctype.h>
  511. X#include <X11/X.h>
  512. X#include <X11/Xlib.h>
  513. X#include <xview/xview.h>
  514. X#include <xview/panel.h>
  515. X#include <xview/font.h>
  516. X
  517. XDisplay *dpy;
  518. XGC      gc;
  519. XXFontStruct *cur_font;
  520. XPanel_item family_item, style_item, scale_item, name_item;
  521. Xint canvas_width;
  522. X
  523. Xmain(argc, argv)
  524. Xint     argc;
  525. Xchar    *argv[];
  526. X{
  527. X    Frame       frame;
  528. X    Panel       panel;
  529. X    Canvas      canvas;
  530. X    XGCValues   gcvalues;
  531. X    Xv_Font     font;
  532. X    void        change_font();
  533. X    void        my_event_proc(), my_resize_proc();
  534. X    int         change_font_by_name();
  535. X    extern void exit();
  536. X
  537. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  538. X
  539. X    frame = (Frame)xv_create(XV_NULL, FRAME,
  540. X        FRAME_LABEL,            argv[0],
  541. X        FRAME_SHOW_FOOTER,      TRUE,
  542. X        NULL);
  543. X
  544. X    panel = (Panel)xv_create(frame, PANEL,
  545. X        PANEL_LAYOUT,           PANEL_VERTICAL,
  546. X        NULL);
  547. X    (void) xv_create(panel, PANEL_BUTTON,
  548. X        PANEL_LABEL_STRING,     "Quit",
  549. X        PANEL_NOTIFY_PROC,      exit,
  550. X        NULL);
  551. X    family_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
  552. X        PANEL_LABEL_STRING,     "Family",
  553. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  554. X        PANEL_DISPLAY_LEVEL,    PANEL_CURRENT,
  555. X        PANEL_CHOICE_STRINGS,
  556. X            FONT_FAMILY_DEFAULT, FONT_FAMILY_DEFAULT_FIXEDWIDTH,
  557. X            FONT_FAMILY_LUCIDA, FONT_FAMILY_LUCIDA_FIXEDWIDTH,
  558. X            FONT_FAMILY_ROMAN, FONT_FAMILY_SERIF, FONT_FAMILY_COUR,
  559. X            FONT_FAMILY_CMR, FONT_FAMILY_GALLENT,
  560. X            FONT_FAMILY_OLGLYPH, FONT_FAMILY_OLCURSOR, NULL,
  561. X        PANEL_NOTIFY_PROC,      change_font,
  562. X        NULL);
  563. X    style_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
  564. X        PANEL_LABEL_STRING,     "Style",
  565. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  566. X        PANEL_DISPLAY_LEVEL,    PANEL_CURRENT,
  567. X        PANEL_CHOICE_STRINGS,
  568. X            FONT_STYLE_DEFAULT, FONT_STYLE_NORMAL, FONT_STYLE_BOLD,
  569. X            FONT_STYLE_ITALIC, FONT_STYLE_BOLD_ITALIC, NULL,
  570. X        PANEL_NOTIFY_PROC,      change_font,
  571. X        NULL);
  572. X    scale_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
  573. X        PANEL_LABEL_STRING,     "Scale",
  574. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  575. X        PANEL_DISPLAY_LEVEL,    PANEL_CURRENT,
  576. X        PANEL_CHOICE_STRINGS,
  577. X            "Small", "Medium", "Large", "X-Large", NULL,
  578. X        PANEL_NOTIFY_PROC,      change_font,
  579. X        NULL);
  580. X    name_item = (Panel_item)xv_create(panel, PANEL_TEXT,
  581. X        PANEL_LABEL_STRING,     "Font Name:",
  582. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  583. X        PANEL_VALUE_DISPLAY_LENGTH, 20,
  584. X        PANEL_NOTIFY_PROC,      change_font_by_name,
  585. X        NULL);
  586. X    window_fit(panel);
  587. X
  588. X    canvas = (Canvas)xv_create(frame, CANVAS,
  589. X        XV_WIDTH,               400,
  590. X        XV_HEIGHT,              200,
  591. X        CANVAS_X_PAINT_WINDOW,  TRUE,
  592. X        CANVAS_RESIZE_PROC,     my_resize_proc,
  593. X        NULL);
  594. X    xv_set(canvas_paint_window(canvas),
  595. X        WIN_EVENT_PROC,         my_event_proc,
  596. X        WIN_CONSUME_EVENT,      LOC_WINENTER,
  597. X        NULL);
  598. X
  599. X    window_fit(frame);
  600. X
  601. X    dpy = (Display *)xv_get(frame, XV_DISPLAY);
  602. X    font = (Xv_Font)xv_get(frame, XV_FONT);
  603. X    cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
  604. X    xv_set(frame, FRAME_LEFT_FOOTER, xv_get(font, FONT_NAME), NULL);
  605. X
  606. X    gcvalues.font = cur_font->fid;
  607. X    gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
  608. X    gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
  609. X    gcvalues.graphics_exposures = False;
  610. X    gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
  611. X        GCForeground | GCBackground | GCFont | GCGraphicsExposures,
  612. X        &gcvalues);
  613. X
  614. X    xv_main_loop(frame);
  615. X}
  616. X
  617. Xvoid
  618. Xmy_event_proc(win, event)
  619. XXv_Window win;
  620. XEvent *event;
  621. X{
  622. X    static int x = 10, y = 10;
  623. X    Window xwin = (Window)xv_get(win, XV_XID);
  624. X    char c;
  625. X
  626. X    if (event_is_up(event))
  627. X        return;
  628. X
  629. X    if (event_is_ascii(event)) {
  630. X        c = (char)event_action(event);
  631. X        XDrawString(dpy, xwin, gc, x, y, &c, 1);
  632. X        /* advance x to next position.  If over edge, linewrap */
  633. X        if ((x += XTextWidth(cur_font, &c, 1)) >= canvas_width) {
  634. X            y += cur_font->max_bounds.ascent +
  635. X                 cur_font->max_bounds.descent;
  636. X            x = 10;
  637. X        }
  638. X    } else if (event_action(event) == ACTION_SELECT) {
  639. X        x = event_x(event);
  640. X        y = event_y(event);
  641. X    } else if (event_action(event) == LOC_WINENTER)
  642. X        win_set_kbd_focus(win, xwin);
  643. X}
  644. X
  645. X/*
  646. X * check resizing so we know how wide to allow the user to type.
  647. X */
  648. Xvoid
  649. Xmy_resize_proc(canvas, width, height)
  650. XCanvas canvas;
  651. Xint width, height;
  652. X{
  653. X    canvas_width = width;
  654. X}
  655. X
  656. Xvoid
  657. Xchange_font(item, value, event)
  658. XPanel_item   item;
  659. XEvent       *event;
  660. X{
  661. X    static int  family, style, scale;
  662. X    char        buf[128];
  663. X    Frame       frame;
  664. X    char        *family_name;
  665. X    char        *style_name;
  666. X    int         scale_value;
  667. X    Xv_Font     font;
  668. X
  669. X    frame = (Frame)xv_get(xv_get(item, PANEL_PARENT_PANEL), XV_OWNER);
  670. X    family_name = (char *)xv_get(family_item, PANEL_CHOICE_STRING,
  671. X                xv_get(family_item, PANEL_VALUE));
  672. X    style_name = (char *)xv_get(style_item, PANEL_CHOICE_STRING,
  673. X                xv_get(style_item, PANEL_VALUE));
  674. X    scale_value = (int) xv_get(scale_item, PANEL_VALUE);
  675. X    xv_set(frame, FRAME_BUSY, TRUE, NULL);
  676. X    font = (Xv_Font)xv_find(frame, FONT,
  677. X        FONT_FAMILY,    family_name,
  678. X        FONT_STYLE,     style_name,
  679. X        /* scale_value happens to coincide with Window_rescale_state */
  680. X        FONT_SCALE,     scale_value,
  681. X        FONT_SIZES_FOR_SCALE, 12, 14, 16, 22,
  682. X        NULL);
  683. X    xv_set(frame, FRAME_BUSY, FALSE, NULL);
  684. X
  685. X    if (!font) {
  686. X        if (item == family_item) {
  687. X            sprintf(buf, "cannot load '%s'", family_name);
  688. X            xv_set(family_item, PANEL_VALUE, family, NULL);
  689. X        } else if (item == style_item) {
  690. X            sprintf(buf, "cannot load '%s'", style_name);
  691. X            xv_set(style_item, PANEL_VALUE, style, NULL);
  692. X        } else {
  693. X            sprintf(buf, "Not available in %s scale.",
  694. X                xv_get(scale_item, PANEL_CHOICE_STRING, scale));
  695. X            xv_set(scale_item, PANEL_VALUE, scale, NULL);
  696. X        }
  697. X        xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
  698. X        return;
  699. X    }
  700. X    if (item == family_item)
  701. X        family = value;
  702. X    else if (item == style_item)
  703. X        style = value;
  704. X    else
  705. X        scale = value;
  706. X    cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
  707. X    XSetFont(dpy, gc, cur_font->fid);
  708. X    sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
  709. X    xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
  710. X}
  711. X
  712. Xchange_font_by_name(item, event)
  713. XPanel_item item;
  714. XEvent *event;
  715. X{
  716. X    char buf[128];
  717. X    char *name = panel_get_value(item);
  718. X    Frame frame = (Frame)xv_get(xv_get(item, XV_OWNER), XV_OWNER);
  719. X    Xv_Font font;
  720. X
  721. X    xv_set(frame, FRAME_BUSY, TRUE, NULL);
  722. X    font = (Xv_Font)font = (Xv_Font)xv_find(frame, FONT,
  723. X        FONT_NAME,      name,
  724. X        NULL);
  725. X    xv_set(frame, FRAME_BUSY, FALSE, NULL);
  726. X
  727. X    if (!font) {
  728. X        sprintf(buf, "cannot load '%s'", name);
  729. X        xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
  730. X        return PANEL_NONE;
  731. X    }
  732. X    cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
  733. X    XSetFont(dpy, gc, cur_font->fid);
  734. X    sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
  735. X    xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
  736. X    return PANEL_NONE;
  737. X}
  738. END_OF_FILE
  739. if test 7864 -ne `wc -c <'xview.demos/fonts/fonts.c'`; then
  740.     echo shar: \"'xview.demos/fonts/fonts.c'\" unpacked with wrong size!
  741. fi
  742. # end of 'xview.demos/fonts/fonts.c'
  743. fi
  744. if test ! -d 'xview.demos/frames' ; then
  745.     echo shar: Creating directory \"'xview.demos/frames'\"
  746.     mkdir 'xview.demos/frames'
  747. fi
  748. if test ! -d 'xview.demos/icons' ; then
  749.     echo shar: Creating directory \"'xview.demos/icons'\"
  750.     mkdir 'xview.demos/icons'
  751. fi
  752. if test ! -d 'xview.demos/menus' ; then
  753.     echo shar: Creating directory \"'xview.demos/menus'\"
  754.     mkdir 'xview.demos/menus'
  755. fi
  756. if test ! -d 'xview.demos/misc' ; then
  757.     echo shar: Creating directory \"'xview.demos/misc'\"
  758.     mkdir 'xview.demos/misc'
  759. fi
  760. if test ! -d 'xview.demos/notice' ; then
  761.     echo shar: Creating directory \"'xview.demos/notice'\"
  762.     mkdir 'xview.demos/notice'
  763. fi
  764. if test ! -d 'xview.demos/notifier' ; then
  765.     echo shar: Creating directory \"'xview.demos/notifier'\"
  766.     mkdir 'xview.demos/notifier'
  767. fi
  768. if test ! -d 'xview.demos/panels' ; then
  769.     echo shar: Creating directory \"'xview.demos/panels'\"
  770.     mkdir 'xview.demos/panels'
  771. fi
  772. if test -f 'xview.demos/panels/item_move.c' -a "${1}" != "-c" ; then 
  773.   echo shar: Will not clobber existing file \"'xview.demos/panels/item_move.c'\"
  774. else
  775. echo shar: Extracting \"'xview.demos/panels/item_move.c'\" \(9801 characters\)
  776. sed "s/^X//" >'xview.demos/panels/item_move.c' <<'END_OF_FILE'
  777. X/*
  778. X * item_move.c
  779. X *    Move items around in a panel using an event handler specific
  780. X * to the panel.  Two panels are created -- the left panel contains
  781. X * panel buttons that allow you to create certain types of items that
  782. X * are put in the second panel.  Use the ADJUST mouse button to move
  783. X * items around in the second panel.
  784. X */
  785. X#include <stdio.h>
  786. X#include <xview/xview.h>
  787. X#include <xview/panel.h>
  788. X
  789. X/* we need handles to the base frame and a panel -- instead of using
  790. X * global variables, we're going to attach the objects to the objects
  791. X * which need to reference them.  Attach using XV_KEY_DATA --
  792. X * here are the keys.
  793. X */
  794. X#define PACKAGE_KEY     100
  795. X#define FRAME_KEY       101
  796. X#define PANEL_KEY       102
  797. X
  798. Xmain(argc, argv)
  799. Xint argc;
  800. Xchar *argv[];
  801. X{
  802. X    Frame       frame;
  803. X    Panel       panel;
  804. X    Panel_item  create_text, item;
  805. X    void        quit(), my_event_proc();
  806. X    int         selected(), create_item();
  807. X
  808. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  809. X
  810. X    frame = (Frame)xv_create(XV_NULL, FRAME,
  811. X        FRAME_LABEL,            "Use Middle Button To Move Items",
  812. X        FRAME_SHOW_FOOTER,      TRUE,
  813. X        NULL);
  814. X    /*
  815. X     * Create panel for known panel items.  Layout panel vertically.
  816. X     */
  817. X    panel = (Panel)xv_create(frame, PANEL,
  818. X        PANEL_LAYOUT,           PANEL_VERTICAL,
  819. X        NULL);
  820. X
  821. X    /*
  822. X     * Create the standard "Quit" button to exit program.
  823. X     */
  824. X    (void) xv_create(panel, PANEL_BUTTON,
  825. X        PANEL_LABEL_STRING,     "Quit",
  826. X        PANEL_NOTIFY_PROC,      quit,
  827. X        XV_KEY_DATA,            FRAME_KEY,      frame,
  828. X        NULL);
  829. X
  830. X    /*
  831. X     * create text panel item, attach the frame as client data for
  832. X     * use by the notify procedure create_item().  Text items inherit
  833. X     * the layout of "label" and "value" from its parent panel.
  834. X     * override for the text item by setting PANEL_LAYOUT explicitly.
  835. X     */
  836. X    create_text = (Panel_item)xv_create(panel, PANEL_TEXT,
  837. X        PANEL_LABEL_STRING,     "Create Button:",
  838. X        PANEL_NOTIFY_PROC,      create_item,
  839. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  840. X        PANEL_VALUE_DISPLAY_LENGTH,     10,
  841. X        NULL);
  842. X
  843. X    /*
  844. X     * panel button determines which type of button to create -- a
  845. X     * button or a message item.  See create_item().
  846. X     */
  847. X    item = (Panel_item)xv_create(panel, PANEL_CHOICE,
  848. X        PANEL_DISPLAY_LEVEL,    PANEL_CURRENT,
  849. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  850. X        PANEL_LABEL_STRING,     "Item type",
  851. X        PANEL_CHOICE_STRINGS,   "Button", "Message", "Text", NULL,
  852. X        NULL);
  853. X    window_fit(panel);
  854. X
  855. X    /* Create a new panel to be used for panel creation.  The panel
  856. X     * from above is no longer referenced.  The panel created here
  857. X     * is the panel used throughout the rest of this program.  The
  858. X     * panel referenced in WIN_RIGHT_OF and XV_HEIGHT is the old one
  859. X     * since the new one isn't created yet.
  860. X     */
  861. X    panel = (Panel)xv_create(frame, PANEL,
  862. X        WIN_RIGHT_OF,           canvas_paint_window(panel),
  863. X        XV_WIDTH,               300,
  864. X        XV_HEIGHT,              xv_get(panel, XV_HEIGHT),
  865. X        OPENWIN_SHOW_BORDERS,   TRUE,
  866. X        NULL);
  867. X
  868. X    /* Install event handling routine for the panel */
  869. X    xv_set(canvas_paint_window(panel),
  870. X        WIN_EVENT_PROC,         my_event_proc,
  871. X        XV_KEY_DATA,            PANEL_KEY,      panel,
  872. X        NULL);
  873. X    /* attach various items to the text item for text_select() */
  874. X    xv_set(create_text,
  875. X        XV_KEY_DATA,            FRAME_KEY,      frame,
  876. X        XV_KEY_DATA,            PACKAGE_KEY,    item,
  877. X        XV_KEY_DATA,            PANEL_KEY,      panel,
  878. X        NULL);
  879. X    window_fit(frame);
  880. X    xv_main_loop(frame);
  881. X}
  882. X
  883. X/*
  884. X * Process events for the panel's subwindow.  This routine gets -all-
  885. X * events that occur in the panel subwindow and does not interfere
  886. X * with the normal processing of events dispatched to panels items.
  887. X * my_event_proc is only interested in ADJUST button events that
  888. X * happen on top of panel items.  When the user clicks and _drags_ the
  889. X * ADJUST button on a panel item, the item is moved to where the mouse
  890. X * moves to.
  891. X */
  892. Xvoid
  893. Xmy_event_proc(window, event)
  894. XXv_Window window;
  895. XEvent *event;
  896. X{
  897. X    static Panel_item   item;
  898. X    static int  x_offset, y_offset;
  899. X    Panel       panel = (Panel)xv_get(window, XV_KEY_DATA, PANEL_KEY);
  900. X    Frame       frame = (Frame)xv_get(panel, XV_OWNER);
  901. X    Rect        *rect, *item_rect;
  902. X    char        buf[64];
  903. X
  904. X    /*
  905. X     * If the mouse is dragging an item, reset its new location.
  906. X     */
  907. X    if (event_action(event) == LOC_DRAG && item) {
  908. X        Panel_item pi;
  909. X        Rect r;
  910. X        /*
  911. X         * Get the rect of item, then *copy* it -- never change data
  912. X         * returned by xv_get().  Modify the copied rect reflecting
  913. X         * new X,Y position of panel item and check to see if it
  914. X         * intersects with any existing panel items.
  915. X         */
  916. X        rect = (Rect *)xv_get(item, XV_RECT);
  917. X        rect_construct(&r, /* see <xview/rect.h> for macros */
  918. X            rect->r_left, rect->r_top, rect->r_width, rect->r_height);
  919. X        r.r_left = event->ie_locx - x_offset;
  920. X        r.r_top = event->ie_locy - y_offset;
  921. X        PANEL_EACH_ITEM(panel, pi)
  922. X            if (pi == item)
  923. X                continue;
  924. X            /* don't let panel items overlap */
  925. X            item_rect = (Rect *)xv_get(pi, XV_RECT);
  926. X            if (rect_intersectsrect(item_rect, &r))
  927. X                return;
  928. X        PANEL_END_EACH
  929. X        /* no overlap -- move panel item. */
  930. X        xv_set(item,
  931. X            PANEL_ITEM_X, r.r_left,
  932. X            PANEL_ITEM_Y, r.r_top,
  933. X            NULL);
  934. X    }
  935. X    /* If it's not the ADJUST button, we're not interested */
  936. X    if (event_action(event) != ACTION_ADJUST)
  937. X        return;
  938. X    /*
  939. X     * next two cases is ADJUST button just-down or just-released
  940. X     */
  941. X    if (event_is_down(event)) {
  942. X        /* Middle button down on an item -- determine panel item */
  943. X        PANEL_EACH_ITEM(panel, item)
  944. X            rect = (Rect *)xv_get(item, XV_RECT);
  945. X            if (rect_includespoint(rect,
  946. X                event->ie_locx, event->ie_locy)) {
  947. X                x_offset = event->ie_locx - rect->r_left;
  948. X                y_offset = event->ie_locy - rect->r_top;
  949. X                break;
  950. X            }
  951. X        PANEL_END_EACH
  952. X        if (item)
  953. X            sprintf(buf, "Moving item: '%s'",
  954. X                (char *)xv_get(item, PANEL_LABEL_STRING));
  955. X        else
  956. X            buf[0] = 0;
  957. X    } else if (item) {
  958. X        char *name = (char *)xv_get(item, PANEL_LABEL_STRING);
  959. X
  960. X        /* test if item is inside panel by comparing XV_RECTs */
  961. X        rect = (Rect *)xv_get(panel, XV_RECT);
  962. X        if (!rect_includespoint(rect,
  963. X            event->ie_locx + rect->r_left,
  964. X            event->ie_locy + rect->r_top)) {
  965. X            /* item is outside the panel -- remove item */
  966. X            xv_destroy(item);
  967. X            sprintf(buf, "Removed '%s' from panel", name);
  968. X        } else
  969. X            sprintf(buf, "'%s' moved to %d %d", name,
  970. X                (int)xv_get(item, XV_X), (int)xv_get(item, XV_Y));
  971. X        /* set "item" to null so that new drag
  972. X         * events don't attempt to move old item.
  973. X         */
  974. X        item = NULL;
  975. X    }
  976. X    xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
  977. X}
  978. X
  979. X/*
  980. X * Callback routine for all panel buttons except "Quit".
  981. X * If the panel item is the text item, determine the name of the new
  982. X * panel button the user wishes to create.  Loop through all the
  983. X * existing panel items looking for one with the same label.  If so,
  984. X * return PANEL_NONE and set the frame's footer with an error message.
  985. X * Otherwise, create a new panel item with the label, reset the text
  986. X * item value and return PANEL_NEXT.
  987. X */
  988. Xint
  989. Xcreate_item(item, event)
  990. XPanel_item item;
  991. XEvent *event;
  992. X{
  993. X    Xv_pkg      *pkg;
  994. X    Panel       panel = (Panel)xv_get(item, XV_KEY_DATA, PANEL_KEY);
  995. X    Frame       frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
  996. X    Panel_item  pi, pkg_item;
  997. X    char        buf[64];
  998. X
  999. X    pkg_item = (Panel_item)xv_get(item, XV_KEY_DATA, PACKAGE_KEY);
  1000. X    (void) strncpy(buf, xv_get(item, PANEL_VALUE), sizeof buf);
  1001. X    if (!buf[0])
  1002. X        return PANEL_NONE;
  1003. X    switch((int)xv_get(pkg_item, PANEL_VALUE)) {
  1004. X        case 1: pkg = PANEL_MESSAGE; break;
  1005. X        case 2: pkg = PANEL_TEXT; break;
  1006. X        default: pkg = PANEL_BUTTON;
  1007. X    }
  1008. X    /* loop thru all panel items and check for item with same name */
  1009. X    PANEL_EACH_ITEM(panel, pi)
  1010. X        if (!strcmp(buf, xv_get(pi, PANEL_LABEL_STRING))) {
  1011. X            xv_set(frame, FRAME_LEFT_FOOTER, "Label Taken", NULL);
  1012. X            return PANEL_NONE;
  1013. X        }
  1014. X    PANEL_END_EACH
  1015. X    (void) xv_create(panel, pkg,
  1016. X        PANEL_LABEL_STRING,     buf,
  1017. X        PANEL_NOTIFY_PROC,      selected,
  1018. X        XV_KEY_DATA,            FRAME_KEY,      frame,
  1019. X        /* only for text items, but doesn't affect other items */
  1020. X        PANEL_VALUE_DISPLAY_LENGTH, 10,
  1021. X        PANEL_LAYOUT,           PANEL_HORIZONTAL,
  1022. X        NULL);
  1023. X    xv_set(item, PANEL_VALUE, "", NULL);
  1024. X    return PANEL_NEXT;
  1025. X}
  1026. X
  1027. X/*
  1028. X * For panel buttons. return XV_OK or XV_ERROR if the item was
  1029. X * selected using the left mouse button or not.
  1030. X */
  1031. Xint
  1032. Xselected(item, event)
  1033. XPanel_item item;
  1034. XEvent *event;
  1035. X{
  1036. X    Frame       frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
  1037. X    char        buf[64];
  1038. X
  1039. X    if (event_action(event) == ACTION_SELECT) {
  1040. X        sprintf(buf, "'%s' selected", xv_get(item, PANEL_LABEL_STRING));
  1041. X        xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
  1042. X        return XV_OK;
  1043. X    }
  1044. X    return XV_ERROR;
  1045. X}
  1046. X
  1047. X/* 
  1048. X * callback for the "Quit" item.  Destroy the frame, which
  1049. X * causes xv_main_loop() to return.
  1050. X */
  1051. Xvoid
  1052. Xquit(item, event)
  1053. XPanel_item item;
  1054. XEvent *event;
  1055. X{
  1056. X    Frame frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
  1057. X    if (event_action(event) == ACTION_SELECT)
  1058. X        xv_destroy_safe(frame);
  1059. X}
  1060. END_OF_FILE
  1061. if test 9801 -ne `wc -c <'xview.demos/panels/item_move.c'`; then
  1062.     echo shar: \"'xview.demos/panels/item_move.c'\" unpacked with wrong size!
  1063. fi
  1064. # end of 'xview.demos/panels/item_move.c'
  1065. fi
  1066. if test ! -d 'xview.demos/scrollbar' ; then
  1067.     echo shar: Creating directory \"'xview.demos/scrollbar'\"
  1068.     mkdir 'xview.demos/scrollbar'
  1069. fi
  1070. if test -f 'xview.demos/scrollbar/scroll_cells.c' -a "${1}" != "-c" ; then 
  1071.   echo shar: Will not clobber existing file \"'xview.demos/scrollbar/scroll_cells.c'\"
  1072. else
  1073. echo shar: Extracting \"'xview.demos/scrollbar/scroll_cells.c'\" \(8544 characters\)
  1074. sed "s/^X//" >'xview.demos/scrollbar/scroll_cells.c' <<'END_OF_FILE'
  1075. X/*
  1076. X * scroll_cells.c -- scroll a bitmap of cells around in a canvas.
  1077. X * The cells are rectangular areas labeled with numbers which may
  1078. X * represent arbitrary data such as icon images.  The cell sizes are
  1079. X * defined to be 64 by 64 aligned in rows and columns.  This example
  1080. X * is used to demonstrate how to configure scrollbars to accommodate
  1081. X * arbitrary data within a window.
  1082. X */
  1083. X#include <stdio.h>
  1084. X#include <X11/X.h>
  1085. X#include <X11/Xlib.h>   /* Using Xlib graphics */
  1086. X#include <xview/xview.h>
  1087. X#include <xview/canvas.h>
  1088. X#include <xview/scrollbar.h>
  1089. X#include <xview/font.h>
  1090. X#include <xview/xv_xrect.h>
  1091. X
  1092. X#define CELL_WIDTH              64
  1093. X#define CELL_HEIGHT             64
  1094. X#define CELLS_PER_HOR_PAGE      5 /* when paging w/scrollbar */
  1095. X#define CELLS_PER_VER_PAGE      5 /* when paging w/scrollbar */
  1096. X#define CELLS_PER_ROW           8
  1097. X#define CELLS_PER_COL           16
  1098. X
  1099. XPixmap          cell_map;       /* pixmap copied onto canvas window */
  1100. XScrollbar       horiz_scrollbar;
  1101. XScrollbar       vert_scrollbar;
  1102. XGC              gc;             /* General usage GC */
  1103. X
  1104. Xmain(argc, argv)
  1105. Xint argc;
  1106. Xchar *argv[];
  1107. X{
  1108. X    Frame       frame;
  1109. X    Canvas      canvas;
  1110. X    void        repaint_proc();
  1111. X
  1112. X    /* Initialize, create frame and canvas... */
  1113. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  1114. X
  1115. X    frame = (Frame)xv_create(XV_NULL, FRAME,
  1116. X        FRAME_LABEL,            argv[0],
  1117. X        FRAME_SHOW_FOOTER,      TRUE,
  1118. X        NULL);
  1119. X
  1120. X    canvas = (Canvas)xv_create(frame, CANVAS,
  1121. X        /* make subwindow the size of a "page" */
  1122. X        XV_WIDTH,               CELL_WIDTH * CELLS_PER_HOR_PAGE,
  1123. X        XV_HEIGHT,              CELL_HEIGHT * CELLS_PER_VER_PAGE,
  1124. X        /* canvas is much larger than the window */
  1125. X        CANVAS_WIDTH,           CELL_WIDTH * CELLS_PER_ROW + 1,
  1126. X        CANVAS_HEIGHT,          CELL_HEIGHT * CELLS_PER_COL + 1,
  1127. X        CANVAS_AUTO_EXPAND,     FALSE,
  1128. X        CANVAS_AUTO_SHRINK,     FALSE,
  1129. X        /* don't retain window -- we'll need
  1130. X         * to repaint it all the time */
  1131. X        CANVAS_RETAINED,        FALSE,
  1132. X        /* we're using Xlib graphics calls in repaint_proc() */
  1133. X        CANVAS_X_PAINT_WINDOW,  TRUE,
  1134. X        CANVAS_REPAINT_PROC,    repaint_proc,
  1135. X        /* we'll be repainting over exposed areas,
  1136. X         * so don't bother clearing */
  1137. X        OPENWIN_AUTO_CLEAR,     FALSE,
  1138. X        NULL);
  1139. X
  1140. X    /*
  1141. X     * Create scrollbars attached to the canvas.  When user clicks
  1142. X     * on cable, page by the page size (PAGE_LENGTH).  Scrolling
  1143. X     * should move cell by cell, not by one pixel (PIXELS_PER_UNIT).
  1144. X     */
  1145. X    vert_scrollbar = xv_create(canvas, SCROLLBAR,
  1146. X        SCROLLBAR_DIRECTION,            SCROLLBAR_VERTICAL,
  1147. X        SCROLLBAR_PIXELS_PER_UNIT,      CELL_HEIGHT,
  1148. X        SCROLLBAR_OBJECT_LENGTH,        CELLS_PER_COL,
  1149. X        SCROLLBAR_PAGE_LENGTH,          CELLS_PER_VER_PAGE,
  1150. X        SCROLLBAR_VIEW_LENGTH,          CELLS_PER_VER_PAGE,
  1151. X        NULL);
  1152. X    horiz_scrollbar = xv_create(canvas, SCROLLBAR,
  1153. X        SCROLLBAR_DIRECTION,            SCROLLBAR_HORIZONTAL,
  1154. X        SCROLLBAR_PIXELS_PER_UNIT,      CELL_WIDTH,
  1155. X        SCROLLBAR_OBJECT_LENGTH,        CELLS_PER_ROW,
  1156. X        SCROLLBAR_PAGE_LENGTH,          CELLS_PER_HOR_PAGE,
  1157. X        SCROLLBAR_VIEW_LENGTH,          CELLS_PER_HOR_PAGE,
  1158. X        NULL);
  1159. X
  1160. X    /*
  1161. X     * create pixmap and draw cells into it ... this is the abstraction.
  1162. X     * The cell_map is copied into the window via XCopyPlane in the
  1163. X     * repaint procedure.
  1164. X     */
  1165. X    {
  1166. X        short           x, y, pt = 0;
  1167. X        Xv_Font         font;
  1168. X        XPoint          points[256]; /* keep Xlib calls to a minimum */
  1169. X        XGCValues       gcvalues;
  1170. X        Display *dpy = (Display *)xv_get(canvas, XV_DISPLAY);
  1171. X
  1172. X        font = (Xv_Font)xv_find(frame, FONT,
  1173. X            FONT_NAME,          "icon",
  1174. X            XV_AUTO_CREATE,     FALSE,
  1175. X            NULL);
  1176. X        cell_map = XCreatePixmap(dpy, DefaultRootWindow(dpy),
  1177. X            CELLS_PER_ROW * CELL_WIDTH + 1,
  1178. X            CELLS_PER_COL * CELL_HEIGHT + 1,
  1179. X            1); /* We only need a 1-bit deep pixmap */
  1180. X
  1181. X        /* Create the gc for the cell_map -- since it is 1-bit deep,
  1182. X         * use 0 and 1 for fg/bg values.  Also, limit number of
  1183. X         * events generated by setting graphics exposures to False.
  1184. X         */
  1185. X        gcvalues.graphics_exposures = False;
  1186. X        gcvalues.background = 0;
  1187. X        gcvalues.foreground = 1;
  1188. X        if (font)
  1189. X            gcvalues.font = (Font)xv_get(font, XV_XID);
  1190. X        gc = XCreateGC(dpy, cell_map,
  1191. X            GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
  1192. X
  1193. X        if (!font) {
  1194. X            /* dot every other pixel */
  1195. X            for (x = 0; x <= CELL_WIDTH * CELLS_PER_ROW; x += 2)
  1196. X                for (y = 0; y <= CELL_HEIGHT * CELLS_PER_COL; y += 2) {
  1197. X                    if (x % CELL_WIDTH != 0 && y % CELL_HEIGHT != 0)
  1198. X                        continue;
  1199. X                    points[pt].x = x, points[pt].y = y;
  1200. X                    if (++pt == sizeof points / sizeof points[0]) {
  1201. X                        XDrawPoints(dpy, cell_map, gc, points, pt,
  1202. X                            CoordModeOrigin);
  1203. X                        pt = 0;
  1204. X                    }
  1205. X                }
  1206. X            if (pt != sizeof points) /* flush remaining points */
  1207. X                XDrawPoints(dpy, cell_map, gc,
  1208. X                            points, pt, CoordModeOrigin);
  1209. X        }
  1210. X        /* Icon font not available.  Instead, label each cell
  1211. X         * with a string describing the cell's coordinates.
  1212. X         */
  1213. X        for (x = 0; x < CELLS_PER_ROW; x++)
  1214. X            for (y = 0; y < CELLS_PER_COL; y++) {
  1215. X                char buf[8];
  1216. X                if (!font) {
  1217. X                    sprintf(buf, "%d,%d", x+1, y+1);
  1218. X                    XDrawString(dpy, cell_map, gc,
  1219. X                        x * CELL_WIDTH + 5, y * CELL_HEIGHT + 25,
  1220. X                        buf, strlen(buf));
  1221. X                } else {
  1222. X                    buf[0] = x + y * CELLS_PER_COL;
  1223. X                    XDrawString(dpy, cell_map, gc,
  1224. X                        x * CELL_WIDTH, y * CELL_HEIGHT, buf, 1);
  1225. X                }
  1226. X            }
  1227. X        /* we're now done with the cell_map, so free gc and create
  1228. X         * a new one based on the window that will use it.  Otherwise,
  1229. X         * the GC may not work because of different depths.
  1230. X         */
  1231. X        if (font)
  1232. X            xv_destroy(gc);
  1233. X        XFreeGC(dpy, gc);
  1234. X        gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
  1235. X        gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
  1236. X        gcvalues.plane_mask = 1L;
  1237. X        gc = XCreateGC(dpy, DefaultRootWindow(dpy),
  1238. X            GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
  1239. X    }
  1240. X
  1241. X    /* shrink frame to minimal size and start notifier */
  1242. X    window_fit(frame);
  1243. X    xv_main_loop(frame);
  1244. X}
  1245. X
  1246. X/*
  1247. X * The repaint procedure is called whenever repainting is needed in
  1248. X * a paint window.  Since the canvas is not retained, this routine
  1249. X * is going to be called anytime the user scrolls the canvas.  The
  1250. X * canvas will handle repainting the portion of the canvas that
  1251. X * was in view and has scrolled onto another viewable portion of
  1252. X * the window.  The xrects parameter will cover the new areas that
  1253. X * were not in view before and have just scrolled into view.  If
  1254. X * the window resizes or if the window is exposed by other windows
  1255. X * disappearing or cycling through the window tree, then the number
  1256. X * of xrects will be more than one and we'll have to copy the new
  1257. X * areas one by one.  Clipping isn't necessary since the areas to
  1258. X * be rendered are set by the xrects value.
  1259. X */
  1260. Xvoid
  1261. Xrepaint_proc(canvas, paint_window, dpy, win, xrects)
  1262. XCanvas          canvas;
  1263. XXv_Window       paint_window;
  1264. XDisplay         *dpy;
  1265. XWindow          win;
  1266. XXv_xrectlist    *xrects;
  1267. X{
  1268. X    int x, y;
  1269. X
  1270. X    x = (int)xv_get(horiz_scrollbar, SCROLLBAR_VIEW_START);
  1271. X    y = (int)xv_get(vert_scrollbar, SCROLLBAR_VIEW_START);
  1272. X
  1273. X    for (xrects->count--; xrects->count >= 0; xrects->count--) {
  1274. X        printf("top-left cell = %d, %d -- %d,%d %d,%d\n", x+1, y+1,
  1275. X            xrects->rect_array[xrects->count].x,
  1276. X            xrects->rect_array[xrects->count].y,
  1277. X            xrects->rect_array[xrects->count].width,
  1278. X            xrects->rect_array[xrects->count].height);
  1279. X
  1280. X        XCopyPlane(dpy, cell_map, win, gc,
  1281. X            xrects->rect_array[xrects->count].x,
  1282. X            xrects->rect_array[xrects->count].y,
  1283. X            xrects->rect_array[xrects->count].width,
  1284. X            xrects->rect_array[xrects->count].height,
  1285. X            xrects->rect_array[xrects->count].x,
  1286. X            xrects->rect_array[xrects->count].y, 1L);
  1287. X    }
  1288. X}
  1289. END_OF_FILE
  1290. if test 8544 -ne `wc -c <'xview.demos/scrollbar/scroll_cells.c'`; then
  1291.     echo shar: \"'xview.demos/scrollbar/scroll_cells.c'\" unpacked with wrong size!
  1292. fi
  1293. # end of 'xview.demos/scrollbar/scroll_cells.c'
  1294. fi
  1295. if test -f 'xview.demos/scrollbar/scroll_cells2.c' -a "${1}" != "-c" ; then 
  1296.   echo shar: Will not clobber existing file \"'xview.demos/scrollbar/scroll_cells2.c'\"
  1297. else
  1298. echo shar: Extracting \"'xview.demos/scrollbar/scroll_cells2.c'\" \(8148 characters\)
  1299. sed "s/^X//" >'xview.demos/scrollbar/scroll_cells2.c' <<'END_OF_FILE'
  1300. X/*
  1301. X * scroll_cells2.c -- scroll a bitmap of cells around in a canvas.
  1302. X * This is a simplified version of scroll_cells.c graphically. That
  1303. X * is, it does not display icons, just rows and columns of cells.
  1304. X * The difference with this version is that it attempts to accomodate
  1305. X * resize events not addressed in the scroll_cells.c.
  1306. X * This new function is at the end of the file.
  1307. X */
  1308. X#include <stdio.h>
  1309. X#include <X11/X.h>
  1310. X#include <X11/Xlib.h>   /* Using Xlib graphics */
  1311. X#include <xview/xview.h>
  1312. X#include <xview/canvas.h>
  1313. X#include <xview/scrollbar.h>
  1314. X#include <xview/xv_xrect.h>
  1315. X
  1316. X#define CELL_WIDTH              64
  1317. X#define CELL_HEIGHT             64
  1318. X#define CELLS_PER_HOR_PAGE      5 /* when paging w/scrollbar */
  1319. X#define CELLS_PER_VER_PAGE      5 /* when paging w/scrollbar */
  1320. X#define CELLS_PER_ROW           16
  1321. X#define CELLS_PER_COL           16
  1322. X
  1323. XPixmap          cell_map;       /* pixmap copied onto canvas window */
  1324. XScrollbar       horiz_scrollbar;
  1325. XScrollbar       vert_scrollbar;
  1326. XGC              gc;             /* General usage GC */
  1327. X
  1328. Xmain(argc, argv)
  1329. Xint argc;
  1330. Xchar *argv[];
  1331. X{
  1332. X    Frame       frame;
  1333. X    Canvas      canvas;
  1334. X    void        repaint_proc(), resize_proc();
  1335. X
  1336. X    /* Initialize, create frame and canvas... */
  1337. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  1338. X
  1339. X    frame = xv_create(XV_NULL, FRAME,
  1340. X        FRAME_LABEL,            argv[0],
  1341. X        FRAME_SHOW_FOOTER,      TRUE,
  1342. X        NULL);
  1343. X
  1344. X    canvas = xv_create(frame, CANVAS,
  1345. X        /* make subwindow the size of a "page" */
  1346. X        XV_WIDTH,               CELL_WIDTH * CELLS_PER_HOR_PAGE,
  1347. X        XV_HEIGHT,              CELL_HEIGHT * CELLS_PER_VER_PAGE,
  1348. X        /* canvas is much larger than the window */
  1349. X        CANVAS_WIDTH,           CELL_WIDTH * CELLS_PER_HOR_PAGE,
  1350. X        CANVAS_HEIGHT,          CELL_HEIGHT * CELLS_PER_VER_PAGE,
  1351. X        /* CANVAS_AUTO_EXPAND,  FALSE, */
  1352. X        /* CANVAS_AUTO_SHRINK,  FALSE, */
  1353. X        /* don't retain window -- we'll repaint it all the time */
  1354. X        CANVAS_RETAINED,        FALSE,
  1355. X        /* We're using Xlib graphics calls in repaint_proc() */
  1356. X        CANVAS_X_PAINT_WINDOW,  TRUE,
  1357. X        CANVAS_REPAINT_PROC,    repaint_proc,
  1358. X        CANVAS_RESIZE_PROC,     resize_proc,
  1359. X        OPENWIN_AUTO_CLEAR,     FALSE,
  1360. X        NULL);
  1361. X
  1362. X    /*
  1363. X     * Create scrollbars attached to the canvas. When user clicks
  1364. X     * on cable, page by the page size (PAGE_LENGTH). Scrolling
  1365. X     * should move cell by cell, not by one pixel (PIXELS_PER_UNIT).
  1366. X     */
  1367. X    vert_scrollbar = xv_create(canvas, SCROLLBAR,
  1368. X        SCROLLBAR_DIRECTION,            SCROLLBAR_VERTICAL,
  1369. X        SCROLLBAR_PIXELS_PER_UNIT,      CELL_HEIGHT,
  1370. X        NULL);
  1371. X    horiz_scrollbar = xv_create(canvas, SCROLLBAR,
  1372. X        SCROLLBAR_DIRECTION,            SCROLLBAR_HORIZONTAL,
  1373. X        SCROLLBAR_PIXELS_PER_UNIT,      CELL_WIDTH,
  1374. X        NULL);
  1375. X
  1376. X    /*
  1377. X     * create pixmap and draw cells into it.  This portion of the
  1378. X     * program could use XCopyArea to render real icons whose sizes
  1379. X     * do not exceed whatever CELL_WIDTH and CELL_HEIGHT are defined
  1380. X     * to be.  The cell_map will be copied into the window via
  1381. X     * XCopyPlane in the repaint procedure.
  1382. X     */
  1383. X    {
  1384. X        short           x, y, pt = 0;
  1385. X        XPoint          points[256];
  1386. X        XGCValues       gcvalues;
  1387. X        Display *dpy = (Display *)xv_get(canvas, XV_DISPLAY);
  1388. X
  1389. X        cell_map = XCreatePixmap(dpy, DefaultRootWindow(dpy),
  1390. X            CELLS_PER_ROW * CELL_WIDTH + 1,
  1391. X            CELLS_PER_COL * CELL_HEIGHT + 1,
  1392. X            1); /* We only need a 1-bit deep pixmap */
  1393. X
  1394. X        /* Create the gc for the cell_map -- since it is 1-bit deep,
  1395. X         * use 0 and 1 for fg/bg values.  Also, limit number of
  1396. X         * events generated by setting geraphics exposures to False.
  1397. X         */
  1398. X        gcvalues.graphics_exposures = False;
  1399. X        gcvalues.background = 0;
  1400. X        gcvalues.foreground = 1;
  1401. X        gc = XCreateGC(dpy, cell_map,
  1402. X            GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
  1403. X
  1404. X        /* dot every other pixel */
  1405. X        for (x = 0; x <= CELL_WIDTH * CELLS_PER_ROW; x += 2)
  1406. X            for (y = 0; y <= CELL_HEIGHT * CELLS_PER_COL; y += 2) {
  1407. X                if (x % CELL_WIDTH != 0 && y % CELL_HEIGHT != 0)
  1408. X                    continue;
  1409. X                points[pt].x = x, points[pt].y = y;
  1410. X                if (++pt == sizeof points / sizeof points[0]) {
  1411. X                    XDrawPoints(dpy, cell_map, gc,
  1412. X                        points, pt, CoordModeOrigin);
  1413. X                    pt = 0;
  1414. X                }
  1415. X            }
  1416. X        if (pt != sizeof points) /* flush out the remaining points */
  1417. X            XDrawPoints(dpy, cell_map, gc,
  1418. X                        points, pt, CoordModeOrigin);
  1419. X        /* label each cell indicating the its coordinates */
  1420. X        for (x = 0; x < CELLS_PER_ROW; x++)
  1421. X            for (y = 0; y < CELLS_PER_COL; y++) {
  1422. X                char buf[8];
  1423. X                sprintf(buf, "%d,%d", x+1, y+1);
  1424. X                XDrawString(dpy, cell_map, gc,
  1425. X                    x * CELL_WIDTH + 5, y * CELL_HEIGHT + 25,
  1426. X                    buf, strlen(buf));
  1427. X            }
  1428. X        /* we're now done with the cell_map, so free gc and
  1429. X         * create a new one based on the window that will use it.
  1430. X         */
  1431. X        XFreeGC(dpy, gc);
  1432. X        gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
  1433. X        gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
  1434. X        gcvalues.plane_mask = 1L;
  1435. X        gc = XCreateGC(dpy, DefaultRootWindow(dpy),
  1436. X            GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
  1437. X    }
  1438. X
  1439. X    /* shrink frame to minimal size and start notifier */
  1440. X    window_fit(frame);
  1441. X    xv_main_loop(frame);
  1442. X}
  1443. X
  1444. X/*
  1445. X * The repaint procedure is called whenever repainting is needed in
  1446. X * a paint window.  Since the canvas is not retained, this routine
  1447. X * is going to be called anytime the user scrolls the canvas.  The
  1448. X * canvas will handle repainting the portion of the canvas that
  1449. X * was in view and has scrolled onto another viewable portion of
  1450. X * the window.  The xrects parameter will cover the new areas that
  1451. X * were not in view before and have just scrolled into view.  If
  1452. X * the window resizes or if the window is exposed by other windows
  1453. X * disappearing or cycling thru the window tree, then the number
  1454. X * of xrects will be more than one and we'll have to copy the new
  1455. X * areas one by one.  Clipping isn't necessary since the areas to
  1456. X * be rendered are set by the xrects value.
  1457. X */
  1458. Xvoid
  1459. Xrepaint_proc(canvas, paint_window, dpy, win, xrects)
  1460. XCanvas          canvas;
  1461. XXv_Window       paint_window;
  1462. XDisplay         *dpy;
  1463. XWindow          win;
  1464. XXv_xrectlist    *xrects;
  1465. X{
  1466. X    int x, y;
  1467. X
  1468. X    x = (int)xv_get(horiz_scrollbar, SCROLLBAR_VIEW_START);
  1469. X    y = (int)xv_get(vert_scrollbar, SCROLLBAR_VIEW_START);
  1470. X
  1471. X    for (xrects->count--; xrects->count >= 0; xrects->count--) {
  1472. X        printf("top-left cell = %d, %d -- %d,%d %d,%d\n", x+1, y+1,
  1473. X            xrects->rect_array[xrects->count].x,
  1474. X            xrects->rect_array[xrects->count].y,
  1475. X            xrects->rect_array[xrects->count].width,
  1476. X            xrects->rect_array[xrects->count].height);
  1477. X
  1478. X        XCopyPlane(dpy, cell_map, win, gc,
  1479. X            x * CELL_WIDTH,
  1480. X            y * CELL_HEIGHT,
  1481. X            xv_get(paint_window, XV_WIDTH),
  1482. X            xv_get(paint_window, XV_HEIGHT),
  1483. X            0, 0, 1L);
  1484. X    }
  1485. X}
  1486. X
  1487. X/*
  1488. X * If the application is resized, then we may wish to reset the
  1489. X * paging and viewing parameters for the scrollbars.
  1490. X */
  1491. Xvoid
  1492. Xresize_proc(canvas, new_width, new_height)
  1493. XCanvas canvas;
  1494. Xint new_width, new_height;
  1495. X{
  1496. X    int page_w = (int)(new_width/CELL_WIDTH);
  1497. X    int page_h = (int)(new_height/CELL_HEIGHT);
  1498. X
  1499. X    if (!vert_scrollbar || !horiz_scrollbar)
  1500. X        return;
  1501. X
  1502. X    printf("new width/height in cells: w = %d, h = %d\n",
  1503. X        page_w, page_h);
  1504. X
  1505. X    xv_set(horiz_scrollbar,
  1506. X        SCROLLBAR_OBJECT_LENGTH,        CELLS_PER_ROW,
  1507. X        SCROLLBAR_PAGE_LENGTH,          page_w,
  1508. X        SCROLLBAR_VIEW_LENGTH,          page_w,
  1509. X        NULL);
  1510. X    xv_set(vert_scrollbar,
  1511. X        SCROLLBAR_OBJECT_LENGTH,        CELLS_PER_COL,
  1512. X        SCROLLBAR_PAGE_LENGTH,          page_h,
  1513. X        SCROLLBAR_VIEW_LENGTH,          page_h,
  1514. X        NULL);
  1515. X}
  1516. END_OF_FILE
  1517. if test 8148 -ne `wc -c <'xview.demos/scrollbar/scroll_cells2.c'`; then
  1518.     echo shar: \"'xview.demos/scrollbar/scroll_cells2.c'\" unpacked with wrong size!
  1519. fi
  1520. # end of 'xview.demos/scrollbar/scroll_cells2.c'
  1521. fi
  1522. if test ! -d 'xview.demos/seln_svc' ; then
  1523.     echo shar: Creating directory \"'xview.demos/seln_svc'\"
  1524.     mkdir 'xview.demos/seln_svc'
  1525. fi
  1526. if test ! -d 'xview.demos/sv_compat' ; then
  1527.     echo shar: Creating directory \"'xview.demos/sv_compat'\"
  1528.     mkdir 'xview.demos/sv_compat'
  1529. fi
  1530. if test ! -d 'xview.demos/textsw' ; then
  1531.     echo shar: Creating directory \"'xview.demos/textsw'\"
  1532.     mkdir 'xview.demos/textsw'
  1533. fi
  1534. if test ! -d 'xview.demos/ttysw' ; then
  1535.     echo shar: Creating directory \"'xview.demos/ttysw'\"
  1536.     mkdir 'xview.demos/ttysw'
  1537. fi
  1538. if test -f 'xview.demos/ttysw/ttycurses.c' -a "${1}" != "-c" ; then 
  1539.   echo shar: Will not clobber existing file \"'xview.demos/ttysw/ttycurses.c'\"
  1540. else
  1541. echo shar: Extracting \"'xview.demos/ttysw/ttycurses.c'\" \(3296 characters\)
  1542. sed "s/^X//" >'xview.demos/ttysw/ttycurses.c' <<'END_OF_FILE'
  1543. X/*
  1544. X * ttycurses.c -- An application that uses a tty subwindow that
  1545. X * emulates a tty so well, you can use curses(3x) routines in it.
  1546. X * This program does not handle resizes -- resizing the base frame
  1547. X * produces unpredictable results.  To handle resizing properly,
  1548. X * the application should install a resize event handler and
  1549. X * call endwin() followed by initscr() to reinitialize curses
  1550. X * to reflect the size of the window.
  1551. X *
  1552. X * cc ttycurses.c -lxview -lcurses -ltermlib
  1553. X */
  1554. X#include <curses.h>
  1555. X#undef WINDOW /* defined by curses.h -- needs to be undefined */
  1556. X#include <xview/xview.h>
  1557. X#include <xview/panel.h>
  1558. X#include <xview/textsw.h>
  1559. X#include <xview/tty.h>
  1560. X
  1561. X/* panel items contain the x,y info for outputting text to the ttysw */
  1562. XPanel_item  x, y, text;
  1563. X
  1564. Xmain(argc,argv)
  1565. Xint     argc;
  1566. Xchar    *argv[];
  1567. X{
  1568. X    Frame       frame;
  1569. X    Panel       panel;
  1570. X    Tty         ttysw;
  1571. X    char        buf[16];
  1572. X    void        output(), exit();
  1573. X
  1574. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  1575. X
  1576. X    frame = xv_create(XV_NULL, FRAME,
  1577. X        FRAME_LABEL,            argv[0],
  1578. X        FRAME_SHOW_FOOTER,      TRUE,
  1579. X        NULL);
  1580. X
  1581. X    panel = (Frame)xv_create(frame, PANEL, NULL);
  1582. X    (void) xv_create(panel, PANEL_BUTTON,
  1583. X        PANEL_LABEL_STRING,             "Quit",
  1584. X        PANEL_NOTIFY_PROC,              exit,
  1585. X        NULL);
  1586. X    (void) xv_create(panel, PANEL_BUTTON,
  1587. X        PANEL_LABEL_STRING,             "Print",
  1588. X        PANEL_NOTIFY_PROC,              output,
  1589. X        NULL);
  1590. X    x = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
  1591. X        PANEL_LABEL_STRING,             "X:",
  1592. X        PANEL_VALUE_DISPLAY_LENGTH,     3,
  1593. X        NULL);
  1594. X    y = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
  1595. X        PANEL_LABEL_STRING,             "Y:",
  1596. X        PANEL_VALUE_DISPLAY_LENGTH,     3,
  1597. X        NULL);
  1598. X    text = (Panel_item)xv_create(panel, PANEL_TEXT,
  1599. X        PANEL_LABEL_STRING,             "Text:",
  1600. X        PANEL_VALUE_DISPLAY_LENGTH,     10,
  1601. X        PANEL_VALUE,                    "X",
  1602. X        NULL);
  1603. X    window_fit(panel);
  1604. X
  1605. X    ttysw = (Tty)xv_create(frame, TTY,
  1606. X        WIN_BELOW,      panel,
  1607. X        WIN_X,          0,
  1608. X        TTY_ARGV,       TTY_ARGV_DO_NOT_FORK,
  1609. X        NULL);
  1610. X    window_fit(frame);
  1611. X
  1612. X    dup2((int)xv_get(ttysw, TTY_TTY_FD), 0); /* dup2 closes 0 first */
  1613. X    dup2((int)xv_get(ttysw, TTY_TTY_FD), 1); /* dup2 closes 1 first */
  1614. X
  1615. X    /* initscr() initializes the curses package and determines
  1616. X     * characteristics about the window as if it were a terminal.
  1617. X     * The curses specific variables, LINES and COLS are now set
  1618. X     * to the row and column sizes of the window.
  1619. X     */
  1620. X    initscr();
  1621. X
  1622. X    xv_set(x, PANEL_MAX_VALUE, COLS-1, NULL);
  1623. X    xv_set(y, PANEL_MAX_VALUE, LINES-1, NULL);
  1624. X    sprintf(buf, "LINES: %d", LINES-1);
  1625. X    xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
  1626. X    sprintf(buf, "COLS: %d", COLS-1);
  1627. X    xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
  1628. X
  1629. X    xv_main_loop(frame);
  1630. X}
  1631. X/*
  1632. X * callback routine for the <print> panel button.  Get the corrdinates
  1633. X * and the text to print on the tty subwindow and use curses library
  1634. X * routines to render the text.
  1635. X */
  1636. Xvoid
  1637. Xoutput()
  1638. X{
  1639. X    int X = (int)xv_get(x, PANEL_VALUE);
  1640. X    int Y = (int)xv_get(y, PANEL_VALUE);
  1641. X    char *Text = (char *)xv_get(text, PANEL_VALUE);
  1642. X    mvaddstr(Y, X, Text);
  1643. X    refresh();
  1644. X}
  1645. END_OF_FILE
  1646. if test 3296 -ne `wc -c <'xview.demos/ttysw/ttycurses.c'`; then
  1647.     echo shar: \"'xview.demos/ttysw/ttycurses.c'\" unpacked with wrong size!
  1648. fi
  1649. # end of 'xview.demos/ttysw/ttycurses.c'
  1650. fi
  1651. echo shar: End of archive 1 \(of 6\).
  1652. cp /dev/null ark1isdone
  1653. MISSING=""
  1654. for I in 1 2 3 4 5 6 ; do
  1655.     if test ! -f ark${I}isdone ; then
  1656.     MISSING="${MISSING} ${I}"
  1657.     fi
  1658. done
  1659. if test "${MISSING}" = "" ; then
  1660.     echo You have unpacked all 6 archives.
  1661.     rm -f ark[1-9]isdone
  1662. else
  1663.     echo You still need to unpack the following archives:
  1664.     echo "        " ${MISSING}
  1665. fi
  1666. ##  End of shell archive.
  1667. exit 0
  1668.